package com.aptech.action.page;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;

import com.aptech.bean.Users;
import com.aptech.dao.UserDao;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport implements RequestAware{
	private Users user;
	private UserDao dao = new UserDao();
	private Map<String, Object> request ;
	

	public String login() {
	
		if (dao.getCorrectUser(user)!=null) {
			request.put("login", "登录值");
			request.put("user", dao.getCorrectUser(user));
			int sex=dao.getCorrectUser(user).getSex();
			if(sex==1){
				request.put("sex", "男");
			}else{
				request.put("sex", "女");
			}
			return SUCCESS;
		} else {
			request.put("message", "用户名或密码错误");
		}
		return ERROR;
	}
	
	public String loginOut(){
		
		request.remove("login");
		
		return SUCCESS;
	}
	

	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

	@Override
	public void setRequest(Map<String, Object> arg0) {
		request=arg0;
	}

}
